clear


**0. Load data

use "$data\MASTER_MATCHED_yearR2.dta", clear

ssc install schemepack, replace
set scheme white_tableau

** 1. Locals & define alternative outcomes
local timevarcontrols Precipitation Temperature
replace treat_percent = 0 if treat_percent == .
replace treat_percent = 100 if treat_percent > 100

bysort cell_uniqueID post: egen baseNF = max(COV_NONFOREST)
gen NetOverNF = Net_Recover/baseNF
g ihsrecover = ln(Net_Recover + sqrt(1+Net_Recover^2))
la var ihsrecover "IHS(Ha recovered)"
** 2. Full sample


xtreg Net_Recover ib(2009).year##c.treat_percent `timevarcontrols', fe i(cell_uniqueID) cluster(cd_mun)

coefplot , ytitle("Marginal effect on annual forest restoration") rescale(35) keep(2009.year *year#c.treat_percent) order(*year ) vertical yline(0, lwidth(thick)) ciopts(lwidth(0.75) lcolor("51 166 166")) msymbol(O) msize(large) mcolor("51 166 166") ///
coeflabels(2000.year#c.treat_percent="00" 2001.year#c.treat_percent="01" 2002.year#c.treat_percent="02" 2003.year#c.treat_percent="03"  2004.year#c.treat_percent="04" 2005.year#c.treat_percent="05" 2006.year#c.treat_percent="06" 2007.year#c.treat_percent="07" 2008.year#c.treat_percent="08" 2009.year="2009" 2010.year#c.treat_percent="10" 2011.year#c.treat_percent="11" 2012.year#c.treat_percent="12"  2013.year#c.treat_percent="13" 2014.year#c.treat_percent="14" 2015.year#c.treat_percent="15" 2016.year#c.treat_percent="16" 2017.year#c.treat_percent="17" 2018.year#c.treat_percent="18" ) groups(2000.year#c.treat_percent - 2008.year#c.treat_percent = "{bf:Pre}" ///
		2010.year#c.treat_percent - 2018.year#c.treat_percent = "{bf:Post}") 

graph export "$figures\Event.png", replace

xtreg ihsrecover ib(2009).year##c.treat_percent `timevarcontrols', fe i(cell_uniqueID) cluster(cd_mun)

coefplot , ytitle("Marginal effect on annual forest restoration") rescale(35) keep(2009.year *year#c.treat_percent) order(*year ) vertical xline (10, lwidth(thick)) yline(0, lwidth(thick)) ciopts(lwidth(0.75) lcolor("51 166 166")) msymbol(O) msize(large) mcolor("242 80 65") ///
coeflabels(2000.year#c.treat_percent="00" 2001.year#c.treat_percent="01" 2002.year#c.treat_percent="02" 2003.year#c.treat_percent="03"  2004.year#c.treat_percent="04" 2005.year#c.treat_percent="05" 2006.year#c.treat_percent="06" 2007.year#c.treat_percent="07" 2008.year#c.treat_percent="08" 2009.year="2009" 2010.year#c.treat_percent="10" 2011.year#c.treat_percent="11" 2012.year#c.treat_percent="12"  2013.year#c.treat_percent="13" 2014.year#c.treat_percent="14" 2015.year#c.treat_percent="15" 2016.year#c.treat_percent="16" 2017.year#c.treat_percent="17" 2018.year#c.treat_percent="18" ) groups(2000.year#c.treat_percent - 2008.year#c.treat_percent = "{bf:Pre}" ///
		2010.year#c.treat_percent - 2018.year#c.treat_percent = "{bf:Post}") 

graph export "$figures\EventIHSRecover.png", replace
